package com.zs.members.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gsj.common.pojo.R;
import com.zs.members.pojo.entity.CouponHistory;
import com.zs.members.dao.CouponHistoryMapper;
import com.zs.members.pojo.vo.CouponHistoryVo;
import com.zs.members.service.CouponHistoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 张硕
 * @since 2021-07-26
 */
@Service
public class CouponHistoryServiceImpl extends ServiceImpl<CouponHistoryMapper, CouponHistory> implements CouponHistoryService {

    @Autowired
    private CouponHistoryMapper couponHistoryMapper;

    @Override
    public R get(Long currentPage, Long pageSize, CouponHistoryVo couponHistoryVo) {
        Page<CouponHistory> page = new Page<>(currentPage,pageSize);
        QueryWrapper<CouponHistory> wrapper = new QueryWrapper<>();
        if (couponHistoryVo.getId()!=null){
            wrapper.like("tch.id",couponHistoryVo.getId());
        }
        if (couponHistoryVo.getCouponId()!=null){
            wrapper.like("tch.coupon_id",couponHistoryVo.getCouponId());
        }
        if (couponHistoryVo.getMemberId()!=null){
            wrapper.like("tch.member_id",couponHistoryVo.getMemberId());
        }
        if (couponHistoryVo.getGetType()!=null){
            wrapper.like("tch.get_type",couponHistoryVo.getGetType());
        }
        if (StringUtils.isNotEmpty(couponHistoryVo.getCreateTime())){
            wrapper.like("tch.create_time",couponHistoryVo.getCreateTime());
        }
        if (StringUtils.isNotEmpty(couponHistoryVo.getCreateTime())){
            wrapper.like("tch.use_status",couponHistoryVo.getUseStatus());
        }
        if (StringUtils.isNotEmpty(couponHistoryVo.getCreateTime())){
            wrapper.like("tch.use_time",couponHistoryVo.getUseTime());
        }
        if (StringUtils.isNotEmpty(couponHistoryVo.getCreateTime())){
            wrapper.like("tch.order_sn",couponHistoryVo.getOrderSn());
        }
        if (StringUtils.isNotEmpty(couponHistoryVo.getCreateTime())){
            wrapper.like("tc.username",couponHistoryVo.getUsername());
        }
        IPage<CouponHistory> couponHistoryIPage = couponHistoryMapper.get(page, wrapper);
        return R.ok().put("records",couponHistoryIPage.getRecords()).put("total",couponHistoryIPage.getTotal());
    }
}
